<template>
	<view class="meedu-filter-box">
		<view class="category1-box" @tap.stop>
			<view class="item" :class="{ active: id2 === 0 }" @click="setCid(0)">全部</view>
			<view class="item" :class="{ active: id2 === item._id }" @click="setCid(item._id)"
				v-for="item in categories2" :key="item._id">{{ item.name }}</view>
		</view>
		<!-- 		<view class="category1-box">
			<view class="item" :class="{ active: id1 === item.id }" @click="setScene(item.id)"
				v-for="(item, index) in categories1" :key="index">{{ item.name }}</view>
		</view> -->

		<!-- 		<view class="filter-button" v-if="categories2.length>0">
			<view class="button-text" :class="{ active: id2 !== 0 }" @click="toggleFilterShowStatus">
				<text>筛选</text>
				<u-icon name="grid"></u-icon>
			</view>

			<view class="meedu-shadow-box" v-if="filterShowStatus" @click="toggleFilterShowStatus()"></view>
		</view> -->
	</view>
</template>

<script>
	export default {
		name: "filter-box",
		props: ["categories1", "categories2", "cid1", "cid2"],
		data() {
			return {
				filterShowStatus: false,
				id1: 0,
				id2: 0,
			};
		},
		mounted() {
			this.id1 = this.cid1;
			this.id2 = this.cid2;
		},
		watch: {
			id2() {
				this.$emit("change", this.id1, this.id2);
			},
			id1() {
				this.$emit("change", this.id1, this.id2);
			},
		},
		methods: {
			toggleFilterShowStatus() {
				this.filterShowStatus = !this.filterShowStatus;
			},
			setScene(scene) {
				this.id1 = scene;
			},
			setCid(id) {
				this.id2 = id;
				this.filterShowStatus = false;
			},
		},
	};
</script>

<style lang="scss">
	.meedu-shadow-box {
		position: fixed;
		top: 0;
		left: 0;
		right: 0;
		bottom: 0;
		z-index: 997;
		background-color: rgba(#000, 0.3);
	}

	.meedu-filter-box {
		width: 100%;
		height: auto;
		box-sizing: border-box;
		padding: 5px 15px;
		background-color: white;
		display: flex;
		flex-flow: column;
		line-height: 30px;
		position: sticky;
		top: 0;
		z-index: 999;

		.category1-box {
			flex: 1;

			.item {
				width: auto;
				height: auto;
				float: left;
				font-size: 14px;
				color: rgba(#333, 0.8);
				margin-right: 10px;

				&.active {
					color: $primary;
					font-weight: bolder;
				}
			}
		}

		.filter-button {
			width: auto;
			height: auto;
			position: relative;

			.button-text {
				font-size: 14px;
				color-profile: #333;

				&.active {
					color: $primary;
				}
			}

			.category2-box {
				position: absolute;
				top: 30px;
				right: 0;
				z-index: 10080;
				width: 166px;
				height: auto;
				box-sizing: border-box;
				padding: 0 15px;
				border-radius: 5px;
				background-color: white;

				.item {
					width: 100%;
					height: auto;
					float: left;
					font-size: 14px;
					color: #333333;
					line-height: 40px;
					white-space: nowrap;
					overflow: hidden;
					text-overflow: ellipsis;

					&.active {
						color: $primary;
						font-weight: bold;
					}
				}
			}
		}
	}
</style>